package com.liyuan.yiqixing.dao;

import com.liyuan.yiqixing.model.Item;
import org.apache.ibatis.annotations.Insert;
import org.apache.ibatis.annotations.Mapper;
import org.apache.ibatis.annotations.Param;
import org.apache.ibatis.annotations.Select;
import org.springframework.stereotype.Repository;

@Mapper
@Repository
public interface ItemDao {
    @Select("select id,hostelName,location,startTime,readCount,imgUrl,left(introduction,30) as introduction from item order by id desc limit #{scale} offset #{offset} ")
    Item[] selectItems(@Param("offset") int offset, @Param("scale") int scale);

    @Insert("insert into item(user,location,introduction,startTime,duration,numberOfPeople,requirement,workContent,additionalInfo,hostelName)" +
            " values(#{user.id},#{location},#{introduction},#{startTime},#{duration},#{numberOfPeople},#{requirement},#{workContent},#{additionalInfo},#{hostelName})")
    void insertItem(Item item);

    @Select("select count(*) from item")
    int sum();

    @Select("select * from item where id = #{id}")
    Item selectItem(@Param("id") Integer id);

    @Select("select id,user,left(introduction,15) as introduction,startTime,endTime from item where id=#{itemId}")
    Item selectPartOfItem(@Param("itemId") Integer itemId);
}
